package com.resourcestore.action;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;

import com.resourcestore.dao.*;
import com.resourcestore.model.*;
import com.resourcestore.utils.CommonUtil;
import com.resourcestore.utils.tag.Pagination;

public class ExpertCourseAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Course course;
	private List<Course> listCourse;
	private CourseDao courseDao = new CourseDao();
	private Major major;
	private List<Major> preInsert;
	private MajorDao majorDao = new MajorDao();
	private CourseCategory courseCategory;
	private List<CourseCategory> preInsertCategory;
	private CourseCategoryDao courseCategoryDao = new CourseCategoryDao();
	private Pagination pagination = new Pagination();
	private ExcellentCourse excellentCourse;
	private List<ExcellentCourse> listExcellentCourse;
	private ExcellentCourseDao excellentCourseDao = new ExcellentCourseDao();
	private CourseTeaClassFK courseTeaFK;
	private List<CourseTeaClassFK> listCourseTeaClassFK;
	private CourseTeaClassFKDao courseTeaFKDao = new CourseTeaClassFKDao();
	private CourseFileSrcPublic courseFileSrcPublic;
	private CourseFileSrcPublicDao courseFileSrcPublicDao = new CourseFileSrcPublicDao();
	private List<CourseFileSrcPublic> listCourseFileSrcPublic;
	private CourseFileSrcPrivate courseFileSrcPrivate;
	private CourseFileSrcPrivateDao courseFileSrcPrivateDao = new CourseFileSrcPrivateDao();
	private List<CourseFileSrcPrivate> listCourseFileSrcPrivate;

	/**
	 * 查询课程 带分页 
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listCourseReadExpert() {

		course = new Course();
		course.setIsPublic(-1);
		pagination.setTotal(courseDao.queryCourseNum(course));
		listCourse = courseDao.selectCoursePage(course, pagination);

		
		for (int i = 0; i < listCourse.size(); i++) {
			
			// 处理是否
			listCourse.get(i).setIsPublicString(this.showIsNot(listCourse.get(i).getIsPublic()));
			
			// 将bigint数字处理为时间格式
			try {
				listCourse.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listCourse.get(i)
								.getGmtCreated()));
				listCourse.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listCourse.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return newpath("/ExpertCourse/listCourseRead.jsp");

	}

	
	/**
	 * 搜索课程带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListCourseReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			course.setMajorName(new String(course.getMajorName().getBytes("iso-8859-1"),"UTF-8"));
			course.setCourseCateName(new String(course.getCourseCateName().getBytes("iso-8859-1"),"UTF-8"));
			course.setCourseName(new String(course.getCourseName().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(courseDao.queryCourseNum(course));
		listCourse = courseDao.selectCoursePage(course,pagination);
		
		
		for (int i = 0; i < listCourse.size(); i++) {
			
			// 处理是否
			listCourse.get(i).setIsPublicString(this.showIsNot(listCourse.get(i).getIsPublic()));
			//将bigint数字处理为时间格式
			try {
				listCourse.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listCourse.get(i).getGmtCreated()));
				listCourse.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listCourse.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listCourseRead.jsp");
	}


	/**
	 * 查询精品课程
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listExcellentCourseReadExpert() {
		excellentCourse = new ExcellentCourse();
		pagination.setTotal(excellentCourseDao.queryExcellentCourseNum(excellentCourse));
		listExcellentCourse = excellentCourseDao.selectExcellentCoursePage(excellentCourse,pagination);

		for (int i = 0; i < listExcellentCourse.size(); i++) {
			try {
				listExcellentCourse.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listExcellentCourse.get(i)
								.getGmtCreated()));
				listExcellentCourse.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listExcellentCourse.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return newpath("/ExpertCourse/listExcellentCourseRead.jsp");
	}
	
	
	/**
	 * 搜索精品课程带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListExcellentCourseReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			excellentCourse.setExceCourseName(new String(excellentCourse.getExceCourseName().getBytes("iso-8859-1"),"UTF-8"));
			excellentCourse.setMajorName(new String(excellentCourse.getMajorName().getBytes("iso-8859-1"),"UTF-8"));
			excellentCourse.setExceCourseMark(new String(excellentCourse.getExceCourseMark().getBytes("iso-8859-1"),"UTF-8"));
			excellentCourse.setAuthor(new String(excellentCourse.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(excellentCourseDao.queryExcellentCourseNum(excellentCourse));
		listExcellentCourse = excellentCourseDao.selectExcellentCoursePage(excellentCourse,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listExcellentCourse.size(); i++) {
			try {
				listExcellentCourse.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listExcellentCourse.get(i).getGmtCreated()));
				listExcellentCourse.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listExcellentCourse.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listExcellentCourseRead.jsp");
	}
	
	/**
	 * 查询教师授课情况
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listCourseTeaClassFKReadExpert() {
		courseTeaFK = new CourseTeaClassFK();
		pagination.setTotal(courseTeaFKDao.queryCourseTeaClassFKNum(courseTeaFK));
		listCourseTeaClassFK = courseTeaFKDao.selectCourseTeaClassFKPage(courseTeaFK,pagination);

		for (int i = 0; i < listCourseTeaClassFK.size(); i++) {
			try {
				listCourseTeaClassFK.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listCourseTeaClassFK.get(i)
								.getGmtCreated()));
				listCourseTeaClassFK.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listCourseTeaClassFK.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listCourseTeaClassFKRead.jsp");
	}
	
	/**
	 * 搜索教师授课情况带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListCourseTeaClassFKReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			courseTeaFK.setRealName(new String(courseTeaFK.getRealName().getBytes("iso-8859-1"),"UTF-8"));
			courseTeaFK.setCourseName(new String(courseTeaFK.getCourseName().getBytes("iso-8859-1"),"UTF-8"));
			courseTeaFK.setAuthor(new String(courseTeaFK.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(courseTeaFKDao.queryCourseTeaClassFKNum(courseTeaFK));
		listCourseTeaClassFK = courseTeaFKDao.selectCourseTeaClassFKPage(courseTeaFK,pagination);
		
		for (int i = 0; i < listCourseTeaClassFK.size(); i++) {
			try {
				listCourseTeaClassFK.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listCourseTeaClassFK.get(i)
								.getGmtCreated()));
				listCourseTeaClassFK.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listCourseTeaClassFK.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listCourseTeaClassFKRead.jsp");
	}
	

	/**
	 * 公共课程文件查询 查询返回List带分页
	 * @throws ParseException 
	 * 
	 */
	public String listCourseFileSrcPublicReadExpert(){
		courseFileSrcPublic = new CourseFileSrcPublic();
		courseFileSrcPublic.setCourseFileCategoryId(-2);
		pagination.setTotal(courseFileSrcPublicDao.queryCourseFileSrcPublicNum(courseFileSrcPublic));
		listCourseFileSrcPublic = courseFileSrcPublicDao.selectCourseFileSrcPublicPage(courseFileSrcPublic,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listCourseFileSrcPublic.size(); i++) {
			//将文件类型代码转换为名称
			listCourseFileSrcPublic.get(i).setCourseFileTypeName(this.showFileCate(listCourseFileSrcPublic.get(i).getCourseFileType()));		
			try {
					listCourseFileSrcPublic.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPublic.get(i).getGmtCreated()));
					listCourseFileSrcPublic.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPublic.get(i).getGmtModified()));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		}
		
		return newpath("/ExpertCourse/listCourseFileSrcPublicRead.jsp");
	}
	
	
	/**
	 * 搜索 公共课程文件查询 根据条件搜索，查询返回List带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListCourseFileSrcPublicReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			courseFileSrcPublic.setCourseFileName(new String(courseFileSrcPublic.getCourseFileName().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPublic.setCourseFileRemark(new String(courseFileSrcPublic.getCourseFileRemark().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPublic.setCourseName(new String(courseFileSrcPublic.getCourseName().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPublic.setAuthor(new String(courseFileSrcPublic.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(courseFileSrcPublicDao.queryCourseFileSrcPublicNum(courseFileSrcPublic));
		listCourseFileSrcPublic = courseFileSrcPublicDao.selectCourseFileSrcPublicPage(courseFileSrcPublic,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listCourseFileSrcPublic.size(); i++) {
			try {
			listCourseFileSrcPublic.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPublic.get(i).getGmtCreated()));
			listCourseFileSrcPublic.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPublic.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listCourseFileSrcPublicRead.jsp");
	}
	
	
	/**
	 *  私有课程文件 查询返回List带分页
	 * @throws ParseException 
	 * 
	 */
	public String listCourseFileSrcPrivateReadExpert(){
		courseFileSrcPrivate = new CourseFileSrcPrivate();
		courseFileSrcPrivate.setCourseFileCategoryId(-2);
		pagination.setTotal(courseFileSrcPrivateDao.queryCourseFileSrcPrivateNum(courseFileSrcPrivate));
		listCourseFileSrcPrivate = courseFileSrcPrivateDao.selectCourseFileSrcPrivatePage(courseFileSrcPrivate,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listCourseFileSrcPrivate.size(); i++) {
			if(listCourseFileSrcPrivate.get(i).getCourseName()!=null){
				listCourseFileSrcPrivate.get(i).setCourseName(listCourseFileSrcPrivate.get(i).getCourseName()+"("+listCourseFileSrcPrivate.get(i).getRealName()+")");
			}
			//将文件类型代码转换为名称
			listCourseFileSrcPrivate.get(i).setCourseFileTypeName(this.showFileCate(listCourseFileSrcPrivate.get(i).getCourseFileType()));	
			try {
					listCourseFileSrcPrivate.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPrivate.get(i).getGmtCreated()));
					listCourseFileSrcPrivate.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPrivate.get(i).getGmtModified()));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		}
		
		return newpath("/ExpertCourse/listCourseFileSrcPrivateRead.jsp");
	}
	
	
	/**
	 * 搜索 私有课程文件 根据条件搜索，查询返回List带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListCourseFileSrcPrivateReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			courseFileSrcPrivate.setCourseFileName(new String(courseFileSrcPrivate.getCourseFileName().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPrivate.setCourseFileRemark(new String(courseFileSrcPrivate.getCourseFileRemark().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPrivate.setCourseName(new String(courseFileSrcPrivate.getCourseName().getBytes("iso-8859-1"),"UTF-8"));
			courseFileSrcPrivate.setAuthor(new String(courseFileSrcPrivate.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(courseFileSrcPrivateDao.queryCourseFileSrcPrivateNum(courseFileSrcPrivate));
		listCourseFileSrcPrivate = courseFileSrcPrivateDao.selectCourseFileSrcPrivatePage(courseFileSrcPrivate,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listCourseFileSrcPrivate.size(); i++) {
			if(listCourseFileSrcPrivate.get(i).getCourseName()!=null){
				listCourseFileSrcPrivate.get(i).setCourseName(listCourseFileSrcPrivate.get(i).getCourseName()+"("+listCourseFileSrcPrivate.get(i).getRealName()+")");
			}
			//将文件类型代码转换为名称
			listCourseFileSrcPrivate.get(i).setCourseFileTypeName(this.showFileCate(listCourseFileSrcPrivate.get(i).getCourseFileType()));	
			try {
			listCourseFileSrcPrivate.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPrivate.get(i).getGmtCreated()));
			listCourseFileSrcPrivate.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listCourseFileSrcPrivate.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertCourse/listCourseFileSrcPrivateRead.jsp");
	}
	
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	public List<Course> getListCourse() {
		return listCourse;
	}

	public void setListCourse(List<Course> listCourse) {
		this.listCourse = listCourse;
	}

	public Major getMajor() {
		return major;
	}

	public void setMajor(Major major) {
		this.major = major;
	}

	public List<Major> getPreInsert() {
		return preInsert;
	}

	public void setPreInsert(List<Major> preInsert) {
		this.preInsert = preInsert;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public List<CourseCategory> getPreInsertCategory() {
		return preInsertCategory;
	}

	public void setPreInsertCategory(List<CourseCategory> preInsertCategory) {
		this.preInsertCategory = preInsertCategory;
	}

	public CourseCategory getCourseCategory() {
		return courseCategory;
	}

	public void setCourseCategory(CourseCategory courseCategory) {
		this.courseCategory = courseCategory;
	}


	public ExcellentCourse getExcellentCourse() {
		return excellentCourse;
	}


	public void setExcellentCourse(ExcellentCourse excellentCourse) {
		this.excellentCourse = excellentCourse;
	}


	public List<ExcellentCourse> getListExcellentCourse() {
		return listExcellentCourse;
	}


	public void setListExcellentCourse(List<ExcellentCourse> listExcellentCourse) {
		this.listExcellentCourse = listExcellentCourse;
	}


	public CourseTeaClassFK getCourseTeaClassFK() {
		return courseTeaFK;
	}


	public void setCourseTeaClassFK(CourseTeaClassFK courseTeaFK) {
		this.courseTeaFK = courseTeaFK;
	}


	public List<CourseTeaClassFK> getListCourseTeaClassFK() {
		return listCourseTeaClassFK;
	}


	public void setListCourseTeaClassFK(List<CourseTeaClassFK> listCourseTeaClassFK) {
		this.listCourseTeaClassFK = listCourseTeaClassFK;
	}


	public CourseFileSrcPublic getCourseFileSrcPublic() {
		return courseFileSrcPublic;
	}


	public void setCourseFileSrcPublic(CourseFileSrcPublic courseFileSrcPublic) {
		this.courseFileSrcPublic = courseFileSrcPublic;
	}


	public List<CourseFileSrcPublic> getListCourseFileSrcPublic() {
		return listCourseFileSrcPublic;
	}


	public void setListCourseFileSrcPublic(List<CourseFileSrcPublic> listCourseFileSrcPublic) {
		this.listCourseFileSrcPublic = listCourseFileSrcPublic;
	}


	public CourseFileSrcPrivate getCourseFileSrcPrivate() {
		return courseFileSrcPrivate;
	}


	public void setCourseFileSrcPrivate(CourseFileSrcPrivate courseFileSrcPrivate) {
		this.courseFileSrcPrivate = courseFileSrcPrivate;
	}


	public List<CourseFileSrcPrivate> getListCourseFileSrcPrivate() {
		return listCourseFileSrcPrivate;
	}


	public void setListCourseFileSrcPrivate(
			List<CourseFileSrcPrivate> listCourseFileSrcPrivate) {
		this.listCourseFileSrcPrivate = listCourseFileSrcPrivate;
	}
	
}
